//
//  LJJMainViewController.swift
//  Swift--weibo
//
//  Created by 李久健 on 16/8/9.
//  Copyright © 2016年 lijiujian. All rights reserved.
//

import UIKit

class LJJMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //实例化自定义tabBar
        let tabBar = LJJTabBar()
        //设置代理
        tabBar.ljjDelegate = self
        
        //只读属性
        //通过 KVC 给只读属性赋值
        setValue(tabBar, forKey: "tabBar")
        //首页
        addChildViewController(LJJHomeViewController(), imgName: "tabbar_home", title: "首页")
        //消息
        addChildViewController(LJJMessageViewController(), imgName: "tabbar_message_center", title: "消息")
        //发现
        addChildViewController(LJJDiscoverViewController(), imgName: "tabbar_discover", title: "发现")
        //我
        addChildViewController(LJJProfileViewController(), imgName: "tabbar_profile", title: "我")
        
    }

    /**
     添加自控制器
     
     - parameter vc:      控制器
     - parameter imgName: 图片名称
     - parameter title:   title
     */
    func addChildViewController(vc: UIViewController,imgName:String,title:String) {
        
        //设置 title
//        vc.navigationItem.title = title
//        vc.tabBarItem.title = title
        vc.title = title
        //设置 title文字
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        //设置图片
        vc.tabBarItem.image = UIImage(named: imgName)
        //AlwaysOriginal 图片渲染方式
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //添加子控制器
        addChildViewController(UINavigationController(rootViewController: vc))
    }
}

extension LJJMainViewController:LJJTabBarDelegate{
    func tabBarButtonClick() {
        print("撰写按钮点击啦")
    }
}
